#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>

int main(int argc, char *argv[])
{
    printf("父/main(%d)进程开始执行\n",getpid());

    //创建一个子进程
    pid_t pid = fork();
    if(pid < 0)
    {
        printf("创建子进程失败\n");
    }
    else if(pid == 0) //子进程
    {
        printf("子进程(%d)开始执行,父进程id =%d\n",getpid(), getppid());
    }
    else //父进程 pid为子进程的id
    {
        printf("父进程(%d)继续执行,子进程id =%d\n",getpid(), pid);
    }
    printf("进程(%d)即将退出\n",getpid);
    return 0;
}